<?php
namespace backend\controllers;

use Yii;
use yii\web\Controller;
use common\collection\Common;
use common\collection\BackendCommon;
use common\helpers\PublicFun;
use backend\config\routeParams;


/**
 * Site controller
 */
class OrderController extends Controller
{

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }

    public  function beforeAction($action){
        if(BackendCommon::init()){
            if(BackendCommon::rbac()){
                return true;
            }else{
                Yii::$app->response->redirect( ['site/error']);
            }
        }else{
            Yii::$app->response->redirect( ['login/index']);
        }
    }
    //首页
    public function actionIndex()
    {
        return $this->render('index');
    }
    //请求列表
    public function actionOrderList()
    {
       $datapost = Yii::$app->request->post();
       $datapost = Common::ArrayFilter($datapost);
       $cookies = Yii::$app->request->cookies;
       $admin = $cookies->get('MytipIdBack')->value;
       $datapost['MytipId'] = $admin;
       if($datapost['type'] == 100){
          $route = 'PCAdMarketOrderGetList';
       }elseif($datapost['type'] == 200){
          $route = 'PCAdSubscribeOrderGetList';
       }else{
          $route = 'PCAdActivityOrderGetList';
       }

       $url = routeParams::HttpUrl($route);
       $result = PublicFun::PostPackage($datapost, $url);
       $result = json_decode($result['Body'],true);
       $ret = [
        'PageNo' => $datapost['PageNo'], 
        'PageSize' => $datapost["PageSize"],
        'total' => $result["TotalCount"],
        'data' => $result['Models']
       ];
       die(json_encode($ret));
    
    }
    //订单详情
    public function actionOrderDetial()
    {
       $datapost = Yii::$app->request->post();
       $datapost = Common::ArrayFilter($datapost);
       $cookies = Yii::$app->request->cookies;
       $admin = $cookies->get('MytipIdBack')->value;
       $datapost['MytipId'] = $admin;
       // print_r($datapost);exit;
       $url = routeParams::HttpUrl('PCOrderDetialGet');
       $result = PublicFun::PostPackage($datapost, $url);
       $result = json_decode($result['Body'],true);
       die(json_encode($result));
    }

}
